package com.lzz.bottomencapsulation.utils;

import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
import com.lzz.bottomencapsulation.R;
/**
 * Toast工具类
 */
public class TUtils {
    private static Toast mToast;

    public static void showShort(Context context, Object content) {
        show(context,  content.toString(), Toast.LENGTH_SHORT);
    }

    public static void show(Context context, String content, int time) {
        if (context == null) return;
        showToast(context,content,time);
    }

    /**
     * 显示对话框
     *
     * @param content 要显示的内容
     */
    public static void showToast(Context context, String content, int time) {
        Toast.makeText(context,content,time).show();
    }

    public static void showImageToas(Context context,View toastview){

        Toast toast=new Toast(context);   //上下文
        toast.setGravity(Gravity.CENTER,0,0);   //位置居中
        toast.setDuration(Toast.LENGTH_SHORT);  //设置短暂提示
        toast.setView(toastview);   //把定义好的View布局设置到Toast里面
        toast.show();
    }

    public static void ToastUtil(Context context, String msg) {
        LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        //自定义布局
        View view = inflater.inflate(R.layout.toast_center, null);
        //自定义toast文本
        TextView textView = view.findViewById(R.id.toast_msg);
        textView.setText(msg);
        if (mToast == null) {
            mToast = new Toast(context);
        }
        //设置toast居中显示
        mToast.setGravity(Gravity.CENTER, 0, 0);
        mToast.setDuration(Toast.LENGTH_SHORT);
        mToast.setView(view);
        mToast.show();
    }
}
